package com.cy.pj.sys.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
import java.time.LocalTime;
import java.util.Map;

@Slf4j
public class TimeAccessInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        testRequestInfo(request,handler);
//        LocalTime now=LocalTime.now();
//        int hour = now.getHour();
//        System.out.println("hour="+hour);
//        log.info("hour{}",hour);
//        if (hour<=6||hour>=10)
//            throw new RuntimeException("请在6~10点之间访问");
        return true;
    }
    private void testRequestInfo(HttpServletRequest request,Object handler){
        String uri=request.getRequestURI();
        System.out.println("request.uri="+uri);
        Map<String, String[]> map = request.getParameterMap();
        System.out.println("request.param.map.keys="+map.keySet());
        HandlerMethod handlerMethod = (HandlerMethod) handler;
        Method method = handlerMethod.getMethod();
        System.out.println("method.name->"+method.getName());
        System.out.println("==preHandle==");
    }
}
